package com.earogya.springsecurity.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.jdbc.JdbcDaoImpl;
import org.springframework.security.provisioning.UserDetailsManager;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

import com.earogya.springsecurity.security.ChangePasswordInterface;
import com.earogya.springsecurity.security.CreateUsersInterface;

/**
 * Used to service account requests.
 * 
 * @author Mularien
 */

public class AdminService extends JdbcDaoImpl{
	public void addUsersToUserGroups(int groupId,String username){
		try{
		int count=getJdbcTemplate(). queryForInt("SELECT count(*) FROM GROUP_MEMBERS WHERE USERNAME=?",new Object[]{username});
			//getJdbcTemplate().query(getUsersByUsernameQuery(), new String[] {username});
			if(count==0){
		getJdbcTemplate(). update(
				
				"INSERT INTO GROUP_MEMBERS(username,group_id) VALUES (?,?)",
				username,groupId);
	}
		}catch(Exception e)
		{
			e.printStackTrace();
		}
		
	}
}

